package com.kyk.controller;

import com.kyk.entity.Users;
import com.kyk.service.IUsersService;
import com.kyk.util.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 用户表 前端控制器
 * </p>
 *
 * @author 凯
 * @since 2025-09-12
 */
@RestController
@RequestMapping("/users")
public class UsersController {
    @Autowired
    IUsersService usersService;

    /**
     * 注册用户
     * @param users
     * @return
     */
    @PostMapping
    public Result addUser(@RequestBody Users users){
        return usersService.addUser(users);
    }

    /**
     * 注册发送验证码
     * @param email
     * @return
     */
    @GetMapping("/registerSendCode")
    public Result registerSendCode(String email){
        return usersService.registerSendCode(email);
    }

    /**
     * 重置密码发送验证码
     * @param email
     * @return
     */
    @GetMapping("/resetSendCode")
    public Result resetSendCode(String email){
        return usersService.resetSendCode(email);
    }

    /**
     * 登录
     * @param users
     * @return
     */
    @PostMapping("/login")
    public Result login(@RequestBody Users users){
        return usersService.login(users);
    }

    /**
     * 重置密码
     * @param users
     * @return
     */
    @PutMapping
    public Result resetPassword(@RequestBody Users users){
        return usersService.resetPassword(users);
    }

    @GetMapping("/current")
    public Result getCurrentUser(
             // 从请求头获取过滤器传递的用户ID和类型
            @RequestHeader("X-User-Id") Long userId,
            @RequestHeader("X-User-Type") String userType) {

        return usersService.getCurrentUser(userId, userType);

    }



}
